<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
         pageEncoding="ISO-8859-1"%>
<%@page import="dto.LoggedUser"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>User Control Panel</title>
        <script type="text/javascript" src="JavaScript/Javascripts.js"></script>
        <script type="text/javascript">
            function msg_user()
            {
                var msg = "<%=session.getAttribute("msg")%>";
                if(msg != 'null') {
                    if(msg == 'Error') {
                        alert("An error occurred, please try after sometime");
                        <%session.setAttribute("msg", null);%>
                    } else {
                        alert("Hi "+msg+", your password has been successfully changed");
                        <%session.setAttribute("msg", null);%>
                    }
                }
                noBack();
            }
            function pswd_frm1()
            {
                var logpass = "<%=((LoggedUser)session.getAttribute("user")).getPassword()%>";
                var currpass=document.password.password1.value;
                if(currpass != "" && logpass != currpass) {
                    alert("Wrong current password");
                    document.password.password1.focus();
                    return false;
                } else {
                    return pswd_frm(currpass);
                }
            }
        </script>
        <link href="CSS/Style.css" rel="stylesheet" type="text/css" />
    </head>
    <body onload="msg_user()" onpageshow="if (event.persisted) noBack();" onunload="">

        <jsp:include page="header.jsp"></jsp:include>
        <div id="menu_wrapper">
            <div id="menu">
                <ul>
                    <li><a href="home.jsp" target="_parent">Home</a></li>
                    <li><a href="about.jsp" target="_parent">About Us</a></li>
                    <li><a href="discuss.jsp" target="_parent">Discussion</a></li>
                    <%
                        if (session.getAttribute("user") == null) {
                    %>
                    <li><a href="Register.jsp" target="current">Register</a></li>
                    <%} else {%>
                    <li><a href="Control.jsp" class="current">User CP</a></li>
                    <%}%>
                </ul>
            </div> <!-- end of menu -->
        </div><!-- end of menu_wrapper -->
        <div id="content_wrapper">
            <div id="sidebar">
                <jsp:include page="login.jsp"/>
                <jsp:include page="subjects.jsp"/>
            </div> <!-- end of sidebar -->

            <div id="content">

                <div class="content_box">

                    <h2>User Control Panel</h2>

                    <h3>Change Password:</h3>

                    <form action="./ChangePassword" name="password" method="post" onsubmit="return pswd_frm1()">
                        <table>
                            <tr>
                                <td>Current Password</td>
                                <td><input type="password" name="password1"/></td>
                            </tr>
                            <tr>
                                <td>New Password</td>
                                <td><input type="password" name="password2"/></td>
                            </tr>
                            <tr>
                                <td>Retype New Password</td>
                                <td><input type="password" name="password3"/></td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="submit" alt="Change Password" value="Change Password"/>
                                </td>
                                <td><input type="reset" alt="Clear" value="Clear"/>
                                </td>
                            </tr>
                        </table>
                    </form>

                    <div class="cleaner"></div>
                </div><div class="content_box_bottom"></div>

            </div> <!-- end of content -->

            <div class="cleaner"></div>

        </div>

        <jsp:include page="footer.jsp"/>
    </body>
</html>